define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

	//查询主校区和分校区
	httpService.post(app.urls.unit_selectSchoolAndAttach,{},function(data){
		if("0000" === data.code){
			$scope.unitList = data.data;
		}else{
			alert(data.msg);
		}
	});
	var hourArray = [];
	for (var i = 6; i < 24; i++) {
		var dataH = {};
		if (i < 10){
			dataH.name= i;
    		dataH.value = '0'+i;
		}else {
			dataH.name= i;
    		dataH.value = ''+i;
		}
		hourArray.push(dataH);
	}
    
	var minuteArray = [];
	for (var i = 0; i < 60; i++) {
		var dataH = {};
 		if (i < 10){
			dataH.name= i;
    		dataH.value = '0'+i;
		}else {
			dataH.name= i;
    		dataH.value = ''+i;
		}
		minuteArray.push(dataH);
	}
 
	$scope.hourList = hourArray;
	$scope.minuteList = minuteArray;
	$scope.form.status = '0';
	$scope.saveForm = function(){
		if($scope.formCheck()){
			$scope.form.start_time=$scope.form.startH + ':' + $scope.form.startM;
			$scope.form.end_time=$scope.form.endH + ':' + $scope.form.endM;
			var interval;
			if($scope.form.startH == $scope.form.endH){
				interval = $scope.form.endM - $scope.form.startM ;
			}else if($scope.form.startH < $scope.form.endH){
				interval=(60 - $scope.form.startM)+$scope.form.endM;
			}
			if($scope.form.startH == $scope.form.endH  &&  $scope.form.startM == $scope.form.endM){
				alert("开始时间不能等于结束时间");
				return ;
			}else if($scope.form.startH > $scope.form.endH){
				alert("开始时间不能大于结束时间");
				return ;
			}else if($scope.form.startH == $scope.form.endH  &&  $scope.form.startM > $scope.form.endM){
				alert("开始时间不能大于结束时间");
				return ;
			}
			httpService.post(app.urls.course_time_selectById,$scope.form,function(data){
				if("0000" === data.code){
					if(data.data == null) {
						httpService.post(app.urls.course_time_insert, $scope.form, function (data) {
							if ("0000" === data.code) {
								eventBusService.publish("content.page.reload", data.data);
								eventBusService.publish("modal.page.close", {});
							} else {
								alert(data.msg);
							}
						});
					}else {
						alert("该上课时间已存在");
					}
				}else{
					alert(data.msg);
				}
			});

		}
	}
}}});